package com.zhao.dota.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.NumberUtil;
import com.zhao.dota.model.LeagueMatch;
import com.zhao.dota.struct.LeagueMatchUsers;
import com.zhao.dota.util.SteamUtil;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class LeagueMatchUsersVo extends LeagueMatch {

    private List<UserHeroVo> users;

    public LeagueMatchUsersVo(LeagueMatchUsers struct) {
        BeanUtil.copyProperties(struct, this);
        String[] userIds = struct.getUserIds().split(",");
        String[] userNames = struct.getUserNames().split(",");
        String[] heroIds = struct.getHeroIds().split(",");
        String[] heroNames = struct.getHeroNames().split(",");
        int min = NumberUtil.min(userIds.length, userNames.length, heroIds.length, heroNames.length);

        List<UserHeroVo> users = new ArrayList<>();
        for (int i = 0; i < min; i++) {
            UserHeroVo user = new UserHeroVo();
            user.setUserId(Integer.parseInt(userIds[i]));
            user.setUserName(userNames[i]);
            user.setHeroId(Integer.parseInt(heroIds[i]));
            user.setHeroName(heroNames[i]);
            user.setHeroAvatar(SteamUtil.getIconUrlByHeroName(user.getHeroName()));
            users.add(user);
        }
        this.users = users;
    }

}
